﻿using Contrats;
using System.ServiceModel;
using Services;
using System.ServiceModel.Description;
using System;

namespace Hosting
{
    class Program
    {
        static void Main(string[] args)
        {
            using(ServiceHost host = new ServiceHost(typeof(CaculatorService)))
            {
                host.AddServiceEndpoint(typeof(ICalculator),new WSHttpBinding(),"http://127.0.0.1:9999/calculatorservice");
                if(host.Description.Behaviors.Find<ServiceMetadataBehavior>()==null)
                {
                    ServiceMetadataBehavior meta = new ServiceMetadataBehavior();
                    meta.HttpGetEnabled = true;
                    meta.HttpGetUrl = new System.Uri("http://127.0.0.1:9999/calculatorservice/metadata");
                    host.Description.Behaviors.Add(meta);
                }
                host.Opened += delegate
                {
                    Console.WriteLine("CalculaorService已经启动，按任意键终止服务！");
                };

                host.Open();
                Console.Read();

            }
        }
    }
}
